package com.iwhalecloud.citybrain.flow.platform.manager.domain.model.eventconfig;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * 事件的触发类型枚举
 *
 * @author songxf
 * @date 2021/07/22
 */
public enum EventMethodEnum {
    NONE(""),
    HTTP_URL("url"),
    GROOVY("groovy"),
    JAVA_CLASS("class");

    private final String code;

    EventMethodEnum(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    /**
     * 根据code查询枚举
     * @param code
     * @return
     */
    public static EventMethodEnum queryEnum(String code) {
        Optional<EventMethodEnum> optional = Arrays.stream(EventMethodEnum.values())
                .filter(p -> Objects.equals(p.getCode(), code))
                .findFirst();
        return optional.orElse(NONE);
    }
}
